package com.gcit.seniorWish.web.modular.system.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gcit.seniorWish.core.node.SelectNode;
import com.gcit.seniorWish.web.common.constant.factory.ConstantFactory;
import com.gcit.seniorWish.web.common.persistence.dao.NoticeMapper;
import com.gcit.seniorWish.web.common.persistence.model.Dict;
import com.gcit.seniorWish.web.common.persistence.model.Notice;
import com.gcit.seniorWish.web.modular.system.dao.NoticeDao;
import com.gcit.seniorWish.web.modular.system.service.INoticeService;

import cn.hutool.core.util.StrUtil;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

	@Resource
	private NoticeDao noticeDao;

	/**
	 * 查询通知类型列表
	 *
	 * @param type
	 * @author tonglu
	 * @date 2018-03-19 下午 3:22
	 */
	@Override
	public List<SelectNode> listBatchTypeForSelect2(String id) {
		List<Dict> typeList = ConstantFactory.me().listDictsByPCode("notice_type");
		List<SelectNode> selectList = new ArrayList<>();
		List<Integer> batchTypeList = null;
		if (StrUtil.isNotBlank(id)) {
			batchTypeList = noticeDao.listNoticeBatchType(id);
		}
		for (Dict dict : typeList) {
			// 数组为空，或者数组中存在当前类型，返回该报考类型
			if (batchTypeList == null || batchTypeList.contains(Integer.parseInt(dict.getValue()))) {
				SelectNode node = new SelectNode();
				node.setId(dict.getValue());
				node.setText(dict.getName());
				selectList.add(node);
			}
		}
		return selectList;
	}
}
